package org.jeecg.modules.business.third.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.modules.business.third.service.ISapOperateService;
import org.jeecg.modules.business.third.service.IThirdCommonService;
import org.jeecg.modules.business.third.strategy.sap.SapOperateStrategyContext;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/*
 * 项目名称:    wms-server-jeecg
 * 接口描述:    //
 * 创建人员:    zhaojun
 * 创建时间:    2023-10-05
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class SapOperateServiceImpl<T> implements ISapOperateService {
    private final IThirdCommonService thirdCommonService;
    private final SapOperateStrategyContext sapOperateStrategyContext;

    @Override
    public List<T> warehouseByTask(String taskId) {
        return this.warehouse(taskId, null, 2);
    }

    @Override
    public List<T> warehouseByOrder(String receiptId) {
        return this.warehouse(null, receiptId, 1);
    }

    @Override
    public List<T> warehouseByOrder(String receiptId, Object data) {
        return this.warehouse(null, receiptId, 1, data);
    }

    @Override
    public List<T> outboundByTask(String taskId) {
        return outbound(taskId, null, 2);
    }

    @Override
    public List<T> outboundByOrder(String receiptId) {
        return outbound(null, receiptId, 1);
    }

    @Override
    public List deliveryByTask(String taskId) {
        return delivery(taskId, null, 2);
    }

    @Override
    public List deliveryOrder(String receiptId) {
        return delivery(null, receiptId, 1);
    }

    private List<T> warehouse(String taskId, String receiptId, Integer type) {
        Map<String, Object> map = thirdCommonService.warehouseReceiptMaterialVoes(taskId, receiptId, type);
        return sapOperateStrategyContext.action(map.get("documentType").toString(), map);
    }

    private List<T> warehouse(String taskId, String receiptId, Integer type,Object data) {
        Map<String, Object> map = thirdCommonService.warehouseReceiptMaterialVoes(taskId, receiptId, type);
        map.put("data",data);
        return sapOperateStrategyContext.action(map.get("documentType").toString(), map);
    }

    private List<T> outbound(String taskId, String receiptId, Integer type) {
        Map<String, Object> map = thirdCommonService.outboundReceiptMaterialVoes(taskId, receiptId, type);
        return sapOperateStrategyContext.action(map.get("documentType").toString(), map);
    }

    private List<T> delivery(String taskId, String receiptId, Integer type) {
        Map<String, Object> map = thirdCommonService.deliveryMaterialVoes(taskId, receiptId, type);
        return sapOperateStrategyContext.action(map.get("documentType").toString(), map);
    }

}
